'use strict';

module.exports = () => {
  return async function loginAuth(ctx, next) {

    const url = ctx.request.url
    
    // api
    if (['POST', 'PUT', 'DELETE'].indexOf(ctx.request.method) > -1 && /\/show\/api\//.test(url)) {
      if (!ctx.session || !ctx.session.id) {
        ctx.helper.returnJson({
          ctx,
          code: -100,
          msg: '未登录'
        })
        return
      }
    }

    await next()
  }
}